package com.sikadwafastdaisfondturbo.pretloan.utils.gilde

import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.sikadwafastdaisfondturbo.pretloan.R

/**
 * 图片加载相关操作
 */
class ImageUtil {
    companion object {
        private var imageUtil: ImageUtil? = null
        @get:Synchronized
        val instance: ImageUtil?
            get() {
                if (imageUtil == null) {
                    imageUtil = ImageUtil()
                }
                return imageUtil
            }
    }

    /**
     * 加载网络图片
     */
    fun loadImageUrl(context: Context?, imageView: ImageView?, imgUrl: String?) {
        if (imageView == null) {
            return
        }
        loadImageUrl(context, imageView, imgUrl, R.mipmap.img_holder)
    }

    /**
     * 加载网络图片
     */
    fun loadImageUrl(context: Context?, imageView: ImageView?, imgUrl: String?, placeholder: Int) {
        if (imageView == null) {
            return
        }
        context?.let {
            Glide.with(it).load(imgUrl).placeholder(placeholder).into(imageView)
        }
    }

    /**
     * 加载本地图片
     */
    fun loadImageRes(context: Context?, imageView: ImageView?, imgRes: Int) {
        if (imageView == null) {
            return
        }
        context?.let {
            Glide.with(it).load(imgRes).into(imageView)
        }
    }
}
